package com.zzyl.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.zzyl.entity.Reservation;


import com.zzyl.mapper.ReservationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class ReservationTask {

    @Autowired
    private ReservationMapper reservationMapper;

    //将状态为0，time<当前时间状态的预约状态修改为3
    @Scheduled(cron = "0 10,40 * * * ?")
    public void canaelExpiredReservation(){
        LambdaQueryWrapper<Reservation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Reservation::getStatus,0)
                .lt(Reservation::getTime, LocalDateTime.now());


        Reservation reservation = new Reservation();
        reservation.setStatus(3);
        reservationMapper.update(reservation,wrapper);
        log.info("取消过期预约成功");
    }
}
